# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=("lua-zlib" "lua53-zlib" "lua52-zlib" "lua51-zlib")
epoch=1
pkgver=1.2
pkgrel=4
url='https://github.com/brimworks/lua-zlib'
pkgdesc='Simple streaming interface to zlib for Lua'
arch=('loong64' 'x86_64')
license=('MIT')
makedepends=('lua' 'lua53' 'lua52' 'lua51')
depends=('zlib')
conflicts=('lua-lzlib')
source=("https://github.com/brimworks/lua-zlib/archive/v$pkgver/lua-zlib-$pkgver.tar.gz")
sha256sums=('26b813ad39c94fc930b168c3418e2e746af3b2e80b92f94f306f6f954cc31e7d')

build() {
  cd "lua-zlib-$pkgver"

  gcc -fPIC $CPPFLAGS $CFLAGS -o lua_zlib.o -c lua_zlib.c
  gcc -shared $LDFLAGS -o zlib.so lua_zlib.o -lz

  gcc -fPIC $CPPFLAGS $CFLAGS -I/usr/include/lua5.3 -o lua_zlib.o -c lua_zlib.c
  gcc -shared $LDFLAGS -o zlib-5.3.so lua_zlib.o -lz

  gcc -fPIC $CPPFLAGS $CFLAGS -I/usr/include/lua5.2 -o lua_zlib.o -c lua_zlib.c
  gcc -shared $LDFLAGS -o zlib-5.2.so lua_zlib.o -lz

  gcc -fPIC $CPPFLAGS $CFLAGS -I/usr/include/lua5.1 -o lua_zlib.o -c lua_zlib.c
  gcc -shared $LDFLAGS -o zlib-5.1.so lua_zlib.o -lz
}

package_lua-zlib() {
  pkgdesc='Simple streaming interface to zlib for Lua 5.4'

  cd "lua-zlib-$pkgver"
  install -D zlib.so "$pkgdir/usr/lib/lua/5.4/zlib.so"
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" README
}

package_lua53-zlib() {
  pkgdesc='Simple streaming interface to zlib for Lua 5.3'

  cd "lua-zlib-$pkgver"
  install -D zlib-5.3.so "$pkgdir/usr/lib/lua/5.3/zlib.so"
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" README
}

package_lua52-zlib() {
  pkgdesc='Simple streaming interface to zlib for Lua 5.2'

  cd "lua-zlib-$pkgver"
  install -D zlib-5.2.so "$pkgdir/usr/lib/lua/5.2/zlib.so"
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" README
}

package_lua51-zlib() {
  pkgdesc='Simple streaming interface to zlib for Lua 5.1'

  cd "lua-zlib-$pkgver"
  install -D zlib-5.1.so "$pkgdir/usr/lib/lua/5.1/zlib.so"
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" README
}
